<?php

namespace app\index\controller;

use app\admin\model\Article;
use app\admin\model\ArticleCategory;
use think\Request;

class ArticleCatController extends CommonController
{
    /**
     * 显示资源列表
     * @return \think\Response
     */
    public function index(){
        $has_id= $this->request->has('cat_id');
        $cat = new ArticleCategory();
        $ar = new Article();
        $cats = [];
        $article = [];
        if (!$has_id){
            $cats  = $cat->where('category_parent',0)->select();
            $article = $ar->where('item',1)->paginate(10);
            $page = $article->render();
        }else{
            $cats  = $cat->where('category_parent',input('get.cat_id'))->select();
            $article = $ar->where('category_id',input('get.cat_id'))->paginate(10);
            $page = $article->render();
        }
     $this->assign('article',$article);
     $this->assign('page',$page);
     $this->assign('cat',$cats);
     return $this->fetch('index');
    }


}
